//
//  CXHToBidNativeAdViewCreator.m
//  CXHAdSDK-ToBid
//
//  Created by 陈坤 on 2025/4/9.
//

#import "CXHToBidNativeAdViewCreator.h"
#import <CXHAdSDK-Core/CXHAdSDKNativeExpressAd.h>
#import <CXHAdSDK-Adapter/CXHAdapterNativeExpressCallBack.h>
#import <WindFoundation/WindFoundation.h>
#import <CXHAdSDK-Adapter/CXHAdapterNativeAdViewDelegate.h>

@interface CXHToBidNativeAdViewCreator ()


@property (nonatomic, strong) UIView<CXHAdapterNativeExpressAdViewDelegate> *expressAdView;

@property (nonatomic, strong) UIView<CXHAdapterNativeAdViewDelegate> *nativeAdView;

@end

@implementation CXHToBidNativeAdViewCreator

- (instancetype)initWithExpressAdView:(UIView<CXHAdapterNativeExpressAdViewDelegate> *)adView {
    self = [super init];
    if (self) {
        _expressAdView = adView;
    }
    return self;
}

- (instancetype)initWithNativeAdView:(UIView<CXHAdapterNativeAdViewDelegate> *)adView{
    self = [super init];
    if (self) {
        _nativeAdView = adView;
    }
    return self;
}

/// 绑定数据
- (void)refreshData{
    [_expressAdView render];
}
/// 设置根视图 （不设置可能造成点击无反应）
- (void)setRootViewController:(UIViewController *)viewController{
    if (_expressAdView) {
        [_expressAdView cxh_setRootViewController:viewController];
    }
    if (_nativeAdView) {
        [_nativeAdView cxh_setRootViewController:viewController];
    }
}
/// 在原生广告视图中注册可点击视图。
- (void)registerContainer:(UIView *)containerView
       withClickableViews:(NSArray<UIView *> *)clickableViews{
    if (_nativeAdView) {
        [containerView insertSubview:_nativeAdView atIndex:0];
        _nativeAdView.frame = CGRectMake(0, 0, containerView.frame.size.width, containerView.frame.size.height);
        NSMutableArray<UIView *> *views = [NSMutableArray array];
        [views addObjectsFromArray:clickableViews];
        [_nativeAdView cxh_registViews:views];
    }
}

- (void)unregisterDataObject{
    if (_nativeAdView) {
        [_nativeAdView cxh_unRegistView];
    }
}

- (void)dealloc {
    WindmillLogDebug(@"CSJ", @"%s", __func__);
}

#pragma mark - Getter
- (UIView *)adLogoView {
    return [self.nativeAdView cxh_logoView];
}

- (UIView *)mediaView {
    return [self.nativeAdView cxh_mediaViewForWidth:self.nativeAdView.frame.size.width];
}

@synthesize imageView;

@synthesize mediaView;

@synthesize imageViewArray;

@synthesize adLogoView;

@synthesize dislikeBtn;

@synthesize interactiveView;

@end
